package main

import (
	"cat/proto/pb"
	"context"
	"fmt"
	polaris "github.com/polarismesh/grpc-go-polaris"
	"log"
	"net"
	"time"
)

type SailService struct {
}

func main() {
	srv := polaris.NewServer(polaris.WithServerApplication("sail"))
	pb.RegisterGreeterServer(srv.GRPCServer(), &SailService{})
	address := "0.0.0.0:40118"
	listen, err := net.Listen("tcp", address)
	if err != nil {
		log.Fatalf("Failed to addr=%s err=%v", address, err)
	}
	err = srv.Serve(listen)
	if err != nil {
		log.Fatal("err")
	}
}

func (s *SailService) SayHello(ctx context.Context, rep *pb.HelloRequest) (*pb.HelloReply, error) {
	fmt.Printf("%v: receive is %s\n", time.Now(), rep.Name)
	reply := &pb.HelloReply{Message: "hello world" + rep.Name}
	return reply, nil
}
